package com.malou.client.util;

import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.store.StoreListener;
import com.extjs.gxt.ui.client.widget.form.ComboBox;

public class MyComboBox extends ComboBox<BeanModel>{
    
	
	public MyComboBox(final ListStore<BeanModel> store, final String property) {
		super();
		setDisplayField(property);
	    setValueField(property);
	    setEmptyText("Seleccione...");
	    setStore(store);  
	    setTypeAhead(true);  
	    setTriggerAction(TriggerAction.ALL);
        setAllowBlank(false);
	    setUseQueryCache(false);
	    setMinChars(0);
	    getStore().addStoreListener(new StoreListener<BeanModel>(){
	    	public void storeDataChanged(StoreEvent<BeanModel> se){
	    		getStore().filter(property,getRawValue().toLowerCase());
	    		System.out.println("filtro:"+getRawValue().toLowerCase());
	    	}
	    });
	    
	    addListener(Events.Expand, new Listener<BaseEvent>() {
			@Override
			public void handleEvent(BaseEvent be) {
				clearSelections();
			}
		});
	}
	
	
}
